<template>
  <div class="movie-card" @click="goToDetail">
    <el-card :body-style="{ padding: '0px' }" shadow="hover">
      <div class="poster-wrapper">
        <img :src="`http://localhost:8000${movie.poster_url}`" :alt="movie.title" class="movie-poster">
      </div>
      <div class="movie-info">
        <div class="title-rating">
          <h3 class="movie-title">{{ movie.title }}</h3>
          <div class="movie-rating">
            <span class="rating-value">{{ movie.rating }}</span>
          </div>
        </div>
        <div class="movie-genres">
          <el-tag v-for="genre in movie.genres" :key="genre" size="small" effect="plain">
            {{ genre }}
          </el-tag>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'

const router = useRouter()
const props = defineProps({
  movie: {
    type: Object,
    required: true
  }
})

const goToDetail = () => {
  router.push(`/movies/${props.movie.id}`)
}
</script>

<style scoped>
.movie-card {
  margin-bottom: 20px;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.movie-card:hover {
  transform: translateY(-5px);
}

.poster-wrapper {
  width: 100%;
  height: 0;
  padding-bottom: 120%;
  position: relative;
  overflow: hidden;
  background-color: #f5f7fa;
}

.movie-poster {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transition: transform 0.3s ease;
}

.movie-info {
  padding: 14px;
}

.title-rating {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.movie-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #303133;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: 10px;
}

.rating-value {
  color: #ff9900;
  font-weight: bold;
  font-size: 16px;
}

.movie-genres {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.movie-genres .el-tag {
  margin-right: 5px;
  margin-bottom: 5px;
}
</style> 